// Procedural abstraction for messages
function DialogCreator (target, type, timeout) {
	$(function () { target = $(target); target.children("span").remove(); });
	return function (message) {
		
		
		
		
		
	}
}

/**
 * @name					jQuery Messages
 * @descripton				jQuery Messages provides a very nice and clean way to inform your users dynamically.
 * @version					1.8.0
 * @requires				jQuery 1.8.0+
 *
 * @author					Sam Vervaeck
 * @author-email			sam@vervaeck.be
 * @author-website			http://sam.vervaeck.be
 *
 * @licence					GNU General Public License - http://www.gnu.org/licenses/gpl-3.0.html
 */

(function($){
	
	// Default configuration values
	var defaults = {
		defaults: {
			hideOnClick: true,
			autoHide: false,
			timeout: 10000,
			className: "message"
		},
		warning: {
			autoHide: false,
			className: "error"
		},
		information: {
			autoHide: true,
			className: "info"
		}
	}
	
	// Messages main function
	function messenger (type) {
	
		return function (message) {
			
			var self = this;
			var config = this.data ('messages');
			
			// Check if the element has been configured
			if (config === undefined) {
				return false;
			}
			
			var settings = $.extend(config.defaults, config[type]);
			
			return this.each (function () {
					
					var $this = $(this);
					var dialog = $('<span class="' + settings.className + '">' + message + '</span>');
					
					function destroy () { dialog.hide("fast", function () { dialog.remove(); }); }
					
					if (settings.hideOnClick) dialog.click(destroy)
					dialog.appendTo($this).show("fast");
					
					$this.stop(true).animate({scrollTop: $this.height()}, "slow");
					if (settings.autoHide) setTimeout(destroy, settings.timeout);
				});
			}
	}
	
	$.fn.extend({
		
		// configuration function
		messages: function (config) {
			return this.data ('messages', $.extend (defaults, config));
		},
		
		// messenger using "information" settings
		inform: messenger ("information"),
		
		// messenger using "warning" settings
		warn: messenger ("warning")
    });
})(jQuery);